import { asyncRoutes, constantRoutes } from '@/router/index'
const state = {
  // 储存静态动态路由 给src\layout\components\Sidebar\index.vue 里的侧边菜单栏显示用的
  routes: []
}
const mutations = {
  setRoutes(state, data) {
    // 恢复静态动态路由，注意顺序
    state.routes = [...constantRoutes, ...data]
  }
}
const actions = {
  filterRouter(store, menus) {
    // 筛选出有去权限的动态路由数组
    const routes = asyncRoutes.filter(el => menus.includes(el.name))
    console.log(routes)
    store.commit('setRoutes', routes)
    return routes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
